/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.chlitina.store.modules.expert.service;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.chlitina.store.common.persistence.Page;
import com.chlitina.store.common.service.BaseService;
import com.chlitina.store.modules.expert.dao.SolutionFaceAndQADao;
import com.chlitina.store.modules.expert.dao.SolutionFaceDao;
import com.chlitina.store.modules.expert.entity.SolutionFaceAndQA;

/**
 * 常见问题Service
 * @author lvbo
 * @version 2013-06-11
 */
@Component
@Transactional(readOnly = true)
public class SolutionFaceAndQAService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(SolutionFaceAndQAService.class);
	@Autowired
	private SolutionFaceDao solutionFaceDao;
	
	@Autowired
	private SolutionFaceAndQADao solutionFaceAndQADao;
	
	public SolutionFaceAndQA get(Long id) {
		return solutionFaceAndQADao.findOne(id);
	}
	
	public Page<SolutionFaceAndQA> find(Page<SolutionFaceAndQA> page, SolutionFaceAndQA solutionFaceAndQA, Long solutionId) {
		DetachedCriteria dc = solutionFaceAndQADao.createDetachedCriteria();
		if (solutionId != null) {
			dc.add(Restrictions.eq("solutionFace.id", solutionId));
		}
		dc.addOrder(Order.desc("id"));
		return solutionFaceAndQADao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(SolutionFaceAndQA solutionFaceAndQA) {
		solutionFaceAndQADao.save(solutionFaceAndQA);
		solutionFaceDao.refresh(solutionFaceAndQA.getSolutionFace());
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		solutionFaceAndQADao.delete(id);
	}
	
}
